package com.ushio.gougouwangguo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum TaskStatusEnum {

    RUNNING("running", "运行中"),
    STOPPED("stopped", "已停止");

    /** 入库值 / 对外序列化值 */
    @EnumValue     // MyBatis-Plus：作为持久化到数据库的值
    @JsonValue     // Jackson：序列化为该值
    private final String value;

    /** 仅用于展示/中文含义 */
    private final String label;

    TaskStatusEnum(String value, String label) {
        this.value = value;
        this.label = label;
    }

    public String getValue() { return value; }
    public String getLabel() { return label; }

    /** 反序列化 & 容错：忽略大小写、空白 */
    @JsonCreator
    public static TaskStatusEnum of(String v) {
        if (v == null) return null;
        String s = v.trim().toLowerCase();
        for (TaskStatusEnum e : values()) {
            if (e.value.equals(s)) return e;
        }
        throw new IllegalArgumentException("Unknown TaskStatusEnum: " + v);
    }

    /** 语义化小工具 */
    public boolean isRunning() { return this == RUNNING; }
    public boolean isStopped() { return this == STOPPED; }
}

